#include "wab_include.h"

static bool openGL_initialized = false;

#define WAB_GL_INIT_CHECK() if(!openGL_initialized) WAB_GL_Init(0, NULL);

void WAB_GL_Init(int argc, char** argv)
{
    glutInit(&argc, argv);

    openGL_initialized = true;
}
void WAB_GL_InitWindow(int32 displayMode, int32 width, int32 height, int32 xPos, int32 yPos)
{
    WAB_GL_INIT_CHECK();
    
    glutInitDisplayMode(displayMode);
    glutInitWindowPosition(xPos, yPos);
    glutInitWindowSize(width, height);
}

void WAB_GL_InitOrtho2D(GLenum firstMatrixMode, GLenum secondMatrixMode, GLdouble worldLeft, GLdouble worldRight, GLdouble worldTop, GLdouble worldBottom)
{
    WAB_GL_INIT_CHECK();

    glMatrixMode(firstMatrixMode);
    glLoadIdentity();
    gluOrtho2D(worldLeft, worldRight, worldTop, worldBottom);
    glMatrixMode(secondMatrixMode);
}

void WAB_GL_CreateViewport(int32 x, int32 y, int32 width, int32 height)
{
    glViewport(x, y, width, height);
}

void WAB_GL_CreateWindow(const char* windowTitle)
{
    glutCreateWindow(windowTitle);
}

void WAB_GL_SetWindowTitle(const char* windowTitle)
{
    glutSetWindowTitle(windowTitle);
}

void WAB_GL_SetDisplayFunc(glDisplayFunc func)
{
    if (func)
        glutDisplayFunc(func);
}

void WAB_GL_SwapBuffer()
{
    glutSwapBuffers();
}

void WAB_GL_MainLoop()
{
    glutMainLoop();
}
